%%%-------------------------------------------------------------------
%%% @author liuwentao
%%% @doc
%%%     角色退出
%%% @end
%%% Created : 15. 7月 2021 15:15
%%%-------------------------------------------------------------------
-module(role_logout).
-author("liuwentao").

-export([
    do/1
]).


-include("common.hrl").
-include("role.hrl").

%% 列表中的函数及返回格式要求如下:
%% fun(Role :: #role{}) -> ok | {ok, NewRole :: #role{}}.
-define(fun_list, [

]).

%% ----------------------------------------------------
%% 外部接口
%% ----------------------------------------------------
%% @doc 执行退出调用
-spec do(Role :: #role{}) -> NewRole :: #role{}.
do(Role) -> do_do(?fun_list, Role).


%% ----------------------------------------------------
%% 私有函数
%% ----------------------------------------------------

%% 执行调用
do_do([], Role) -> Role;
do_do([{M, F} | T], Role = #role{name = Name}) ->
    case catch erlang:apply(M, F, [Role]) of
        ok ->
            do_do(T, Role);
        {ok, NewRole} when is_record(NewRole, role) ->
            do_do(T, NewRole);
        Err ->
            ?ERR("角色[~ts]执行退出调用[~w:~w]时发生异常: ~w", [Name, M, F, Err]),
            do_do(T, Role)
    end.
